package com.corpdata.app.project.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;
import com.corpdata.app.project.entity.ProjectStation;
import com.corpdata.app.project.service.ProjectPartitionService;
import com.corpdata.app.project.service.ProjectStationService;
import com.corpdata.common.domain.DataGridRequestDTO;
import com.corpdata.common.result.Result;
import com.corpdata.system.log.OptLog;
import com.corpdata.system.log.OptLogConstant;
import com.corpdata.system.log.WebLog;
import com.corpdata.core.base.BaseController;

/**
 * 分区工位
 * 
 * @author wu
 * @email 64088839@qq.com
 * @date 2018-06-08 15:23:00
 */
 
@Controller
@RequestMapping("app/projectStation")
public class ProjectStationController extends BaseController{

	@Autowired
	private ProjectStationService projectStationService;
	
	@Autowired
	private ProjectPartitionService partitionServ;
	
	//新增页面
	@GetMapping("/add/{id}")
	public String add(@PathVariable("id") String id,ModelMap map){
		map.put("id", id);
		return "app/project/station/station_add";
	}
	
	//保存数据
	@WebLog()
	@ResponseBody
	@RequestMapping("/save")
	@OptLog(info=OptLogConstant.INFO_ADD+"工位",module="工位")
	public Result save(ProjectStation record,String partitionId,String stationNames){
		return projectStationService.insert(partitionId, stationNames);
	}
	
	//编辑页面
	@RequestMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id,ModelMap map){
		map.put("record", projectStationService.findById(id));
		return "app/project/projectStation_edit";
	}
	
	//更新数据
	@WebLog()
	@ResponseBody
	@RequestMapping("/update")
	@OptLog(info=OptLogConstant.INFO_MOF+"工位",module="工位")
	public Result update(ProjectStation record){
		return projectStationService.update(record);
	}
	
	//删除
	@WebLog()
	@ResponseBody
	@PostMapping("/delete")
	@OptLog(info=OptLogConstant.INFO_DEL+"工位",module="工位")
	public Result delete(String id){
		return projectStationService.deleteById(id);
	}
	
	//批量删除
	@WebLog()
	@ResponseBody
	@PostMapping("/deletes")
	public Result deletes(@RequestParam("ids[]") String[] ids){
		return projectStationService.deleteByIds(ids);
	}
	
	//详情页面
	@GetMapping("/details/{id}")
	public String details(ModelMap map,@PathVariable("id") String id){
		map.put("record", projectStationService.findById(id));
	    return "app/project/projectStation_details";
	}
	
	//列表页面
	@GetMapping("/list")
	public String list(){
	    return "app/project/projectStation_list";
	}
	
	//列表数据
	@ResponseBody
	@RequestMapping("/listdata")
	public String findByPage(DataGridRequestDTO dgRequest){
		return projectStationService.findByPage(dgRequest);
	}

	//列表页面
	@GetMapping("/index")
	public String index(){
	    return "app/project/station/station_index";
	}
	//手动分配工位
	@GetMapping("/manualAdd/{partitionId}_{gwCount}_{stationId}_{contractId}")
	public String manualAdd(ModelMap map,@PathVariable("partitionId") String partitionId,@PathVariable("gwCount") String gwCount,@PathVariable("stationId") String stationId,@PathVariable("contractId") String contractId){
		map.put("partition", partitionServ.findById(partitionId));
		map.put("gwCount", gwCount);
		map.put("stationId", stationId);
		map.put("contractId", contractId);
	    return "app/project/station/station_manual_add";
	}
}
